1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module sourceview.Snippet; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.c.functions; 30 private import gobject.ObjectG; 31 private import sourceview.SnippetChunk; 32 private import sourceview.SnippetContext; 33 private import sourceview.c.functions; 34 public import sourceview.c.types; 35 36 37 /** 38 * Quick insertion code snippets. 39 * 40 * The `GtkSourceSnippet` represents a series of chunks that can quickly be 41 * inserted into the [class@View]. 42 * 43 * Snippets are defined in XML files which are loaded by the 44 * [class@SnippetManager]. Alternatively, applications can create snippets 45 * on demand and insert them into the [class@View] using 46 * [method@View.push_snippet]. 47 * 48 * Snippet chunks can reference other snippet chunks as well as post-process 49 * the values from other chunks such as capitalization. 50 */ 51 public class Snippet : ObjectG 52 { 53 /** the main Gtk struct */ 54 protected GtkSourceSnippet* gtkSourceSnippet; 55 56 /** Get the main Gtk struct */ 57 public GtkSourceSnippet* getSnippetStruct(bool transferOwnership = false) 58 { 59 if (transferOwnership) 60 ownedRef = false; 61 return gtkSourceSnippet; 62 } 63 64 /** the main Gtk struct as a void* */ 65 protected override void* getStruct() 66 { 67 return cast(void*)gtkSourceSnippet; 68 } 69 70 /** 71 * Sets our main struct and passes it to the parent class. 72 */ 73 public this (GtkSourceSnippet* gtkSourceSnippet, bool ownedRef = false) 74 { 75 this.gtkSourceSnippet = gtkSourceSnippet; 76 super(cast(GObject*)gtkSourceSnippet, ownedRef); 77 } 78 79 80 /** */ 81 public static GType getType() 82 { 83 return gtk_source_snippet_get_type(); 84 } 85 86 /** 87 * Creates a new #GtkSourceSnippet 88 * 89 * Params: 90 * trigger = the trigger word 91 * languageId = the source language 92 * 93 * Returns: A new #GtkSourceSnippet 94 * 95 * Throws: ConstructionException GTK+ fails to create the object. 96 */ 97 public this(string trigger, string languageId) 98 { 99 auto __p = gtk_source_snippet_new(Str.toStringz(trigger), Str.toStringz(languageId)); 100 101 if(__p is null) 102 { 103 throw new ConstructionException("null returned by new"); 104 } 105 106 this(cast(GtkSourceSnippet*) __p, true); 107 } 108 109 /** 110 * Appends @chunk to the @snippet. 111 * 112 * This may only be called before the snippet has been expanded. 113 * 114 * Params: 115 * chunk = a #GtkSourceSnippetChunk 116 */ 117 public void addChunk(SnippetChunk chunk) 118 { 119 gtk_source_snippet_add_chunk(gtkSourceSnippet, (chunk is null) ? null : chunk.getSnippetChunkStruct()); 120 } 121 122 /** 123 * Does a deep copy of the snippet. 124 * 125 * Returns: A new #GtkSourceSnippet 126 */ 127 public Snippet copy() 128 { 129 auto __p = gtk_source_snippet_copy(gtkSourceSnippet); 130 131 if(__p is null) 132 { 133 return null; 134 } 135 136 return ObjectG.getDObject!(Snippet)(cast(GtkSourceSnippet*) __p, true); 137 } 138 139 /** 140 * Gets the context used for expanding the snippet. 141 * 142 * Returns: an #GtkSourceSnippetContext 143 */ 144 public SnippetContext getContext() 145 { 146 auto __p = gtk_source_snippet_get_context(gtkSourceSnippet); 147 148 if(__p is null) 149 { 150 return null; 151 } 152 153 return ObjectG.getDObject!(SnippetContext)(cast(GtkSourceSnippetContext*) __p); 154 } 155 156 /** 157 * Gets the description for the snippet. 158 */ 159 public string getDescription() 160 { 161 return Str.toString(gtk_source_snippet_get_description(gtkSourceSnippet)); 162 } 163 164 /** 165 * Gets the current focus for the snippet. 166 * 167 * This is changed as the user tabs through focus locations. 168 * 169 * Returns: The focus position, or -1 if unset. 170 */ 171 public int getFocusPosition() 172 { 173 return gtk_source_snippet_get_focus_position(gtkSourceSnippet); 174 } 175 176 /** 177 * Gets the language-id used for the source snippet. 178 * 179 * The language identifier should be one that matches a 180 * source language [property@Language:id] property. 181 * 182 * Returns: the language identifier 183 */ 184 public string getLanguageId() 185 { 186 return Str.toString(gtk_source_snippet_get_language_id(gtkSourceSnippet)); 187 } 188 189 /** 190 * Gets the number of chunks in the snippet. 191 * 192 * Note that not all chunks are editable. 193 * 194 * Returns: The number of chunks. 195 */ 196 public uint getNChunks() 197 { 198 return gtk_source_snippet_get_n_chunks(gtkSourceSnippet); 199 } 200 201 /** 202 * Gets the name for the snippet. 203 */ 204 public string getName() 205 { 206 return Str.toString(gtk_source_snippet_get_name(gtkSourceSnippet)); 207 } 208 209 /** 210 * Gets the chunk at @nth. 211 * 212 * Params: 213 * nth = the nth chunk to get 214 * 215 * Returns: an #GtkSourceSnippetChunk 216 */ 217 public SnippetChunk getNthChunk(uint nth) 218 { 219 auto __p = gtk_source_snippet_get_nth_chunk(gtkSourceSnippet, nth); 220 221 if(__p is null) 222 { 223 return null; 224 } 225 226 return ObjectG.getDObject!(SnippetChunk)(cast(GtkSourceSnippetChunk*) __p); 227 } 228 229 /** 230 * Gets the trigger for the source snippet. 231 * 232 * A trigger is a word that can be expanded into the full snippet when 233 * the user presses Tab. 234 * 235 * Returns: A string or %NULL 236 */ 237 public string getTrigger() 238 { 239 return Str.toString(gtk_source_snippet_get_trigger(gtkSourceSnippet)); 240 } 241 242 /** 243 * Sets the description for the snippet. 244 * 245 * Params: 246 * description = the snippet description 247 */ 248 public void setDescription(string description) 249 { 250 gtk_source_snippet_set_description(gtkSourceSnippet, Str.toStringz(description)); 251 } 252 253 /** 254 * Sets the language identifier for the snippet. 255 * 256 * This should match the [property@Language:id] identifier. 257 * 258 * Params: 259 * languageId = the language identifier for the snippet 260 */ 261 public void setLanguageId(string languageId) 262 { 263 gtk_source_snippet_set_language_id(gtkSourceSnippet, Str.toStringz(languageId)); 264 } 265 266 /** 267 * Sets the name for the snippet. 268 * 269 * Params: 270 * name = the snippet name 271 */ 272 public void setName(string name) 273 { 274 gtk_source_snippet_set_name(gtkSourceSnippet, Str.toStringz(name)); 275 } 276 277 /** 278 * Sets the trigger for the snippet. 279 * 280 * Params: 281 * trigger = the trigger word 282 */ 283 public void setTrigger(string trigger) 284 { 285 gtk_source_snippet_set_trigger(gtkSourceSnippet, Str.toStringz(trigger)); 286 } 287 }